package game.roles.enemys;

import com.javaGame.util.MusicUtil;
import game.frame.MainFrame;
import game.roles.gifts.Gift1;
import game.roles.visual.Boom;
import game.roles.Role;

import java.awt.*;
import java.util.Random;

/**
 * @author liuyulai
 * Created with IntelliJ IDEA.
 * Date: 21.5.8
 * Time: 9:13
 * Description: 敌人角色
 */
public abstract class EnemyRole extends Role {
    /**
     * 怪物生命
     */
    protected int hp;

    /**
     * 最高生命
     */
    protected int maxHp;

    /**
     * 怪物的经验
     */
    protected int exp;


    public EnemyRole(int x, int y, int width, int height, int hp, int exp) {
        super(x, y, width, height);
        //初始化生命值
        this.hp = hp;
        //初始化经验值
        this.exp = exp;
        this.maxHp = hp;
    }


    /**
     * 怪物被击中方法，怪物被击中后可以掉随机礼物
     */
    public void byHit(int deHp) {
        this.hp -= deHp;
        //怪物死亡时将怪物直接移除集合
        if (this.hp <= 0) {
            MainFrame.playerExp += this.exp;
            MainFrame.sp += this.exp / 10;
            MainFrame.roleList.remove(this);
            new MusicUtil("music/peoDied.mp3", false);
            setBoomWay();
            int x = new Random().nextInt(10);
            if (x <= 1) {
                MainFrame.roleList.add(new Gift1(this.x, this.y));
            }
        }
    }

    /**
     * 怪物爆炸效果,一定概率可以生成出礼物,可以被重写方便进行设置
     */
    public void setBoomWay() {
        MainFrame.roleList.add(new Boom(this.x, this.y));
    }

}
